package com.zztest2;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections4.MultiValuedMap;
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;

/**
 * Hello world!
 *
 */
public class App2 {
	public static void main(String[] args) {
		System.out.println("Hello World!");
		User user1 = createUser(1004L, "zhangsan", "group1", 55);
		User user2 = createUser(1007L, "lisi", "group3", 28);
		User user3 = createUser(1001L, "wangwu", "group1", 19);
		User user4 = createUser(1005L, "zhaoliu", "group2", 17);
		User user5 = createUser(1009L, "chenqi", "group3", 29);
		User user6 = createUser(1002L, "wukong", "group1", 37);
		User user7 = createUser(1008L, "bajie", "group2", 8);
		User user8 = createUser(1006L, "saseng", "group1", 26);
		User user9 = createUser(1003L, "bailongma", "group2", 13);
		List<User> list = new ArrayList<>();
		list.add(user1);
		list.add(user2);
		list.add(user3);
		list.add(user4);
		list.add(user5);
		list.add(user6);
		list.add(user7);
		list.add(user8);
		list.add(user9);
		MultiValuedMap<String, User> multiMap = new ArrayListValuedHashMap<String, User>();
		for (int i = 0; i < list.size(); i++) {
			User user = list.get(i);
			String group = user.getGroup();
			multiMap.put(group, user);
		}
		Object object1 = multiMap.get("group1");
		System.out.println(object1);
		Object object2 = multiMap.get("group2");
		System.out.println(object2);
		Object object3 = multiMap.get("group3");
		System.out.println(object3);
	}

	private static User createUser(Long id, String name, String group, Integer age) {
		User user = new User();
		user.setId(id);
		user.setName(name);
		user.setGroup(group);
		user.setAge(age);
		return user;
	}
}
